/*
 * $QNXLicenseC:
 * Copyright 2017, QNX Software Systems.
 * Copyright 2017 NXP
 *
 * Licensed under the Apache License, Version 2.0 (the "License"). You
 * may not reproduce, modify or distribute this software except in
 * compliance with the License. You may obtain a copy of the License
 * at: http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OF ANY KIND, either express or implied.
 *
 * This file may contain contributions from others, either as
 * contributors under the License or as licensors under other terms.
 * Please review this entire file for other proprietary rights or license
 * notices, as well as the QNX Development Suite License Guide at
 * http://licensing.qnx.com/license-guide/ for other information.
 * $
 */


#ifndef INCL__VCAPTURE_IMX8X_EXT__H
#define INCL__VCAPTURE_IMX8X_EXT__H

#include <vcapture/capture.h>

/**************************************************************/
/* Note:                                                      */
/* If you add new properties to this file, please add them to */
/* lib/capture/props-validation.c for validation too.         */
/**************************************************************/

#define CAPTURE_DEINTERLACE_IMX8X_MANUAL_WEAVE_MODE     100
	/* This mode is used as a workaround for ERR010919 (ISI De-interlacing is not supported for NTSC format).
	 * In some projects, this seems to be the only way to capture a NTSC stream stably. Please note there is
	 * only one buffer being used for capture in this case.
	 * According to the errata, the issue only exist on A0 silicon, and will be fixed on B0 silicon. */

#define CAPTURE_DEI_IMX8X_WEAVE_FLAG_AVERAGING		(1 << 31)
	/* This is a bit definition for CAPTURE_PROPERTY_DEINTERLACE_FLAGS.
	 * If set, averaging operation will be performed on the WOVEN frames, to try to avoid the "combing" artifacts */

#define CAPTURE_PROPERTY_IMX8X_NUM_EARLY_VSYNC_IGNORED	CAPTURE_PROPERTY('I','X','N','V')
	/* R/W		int				Number of EARLY_VSYNC interrupts to be ignored (4 by default)
	 * It is part of the workaround for the random wrong field order issue when WEAVE deinterlace is used.
	 * The capture hardware doesn't handle the abnormal stream well --- for instance, the field order switches
	 * as time goes on, or the stream resumes after being interrupted --- hence a workaround was developed to
	 * detect whether the incoming field order is inverted or not by making use of the EARLY_VSYNC IRQ.
	 * The property instructs the library to ignore a specified number of EARLY_VSYNC interrupts before taking
	 * the "field order correction" action.
	 * NOTE:
	 * - The workaround only works for the stream where the top field and bottom field are with different length.
	 * - The number of EARLY_VSYNC interrupts to be ignored is related to the characteristics of the decoder output.*/

#define CAPTURE_PROPERTY_IMX8X_SOURCE_FLAGS		CAPTURE_PROPERTY('I','X','S','F')
	/* R/W		int				the source characteristics (bit field) */
#define CAPTURE_IMX8X_SRC_FLAG_CSI2_2_FLDS_IN_1_FRM	(1 << 0)
	/* Set this bit when a set of Frame Start (FS)/Frame End(FE) is skipped between field 1 and field 2:
	  * FS -> Field 1 -> Field 2 -> FE -> FS -> Field 1 -> Field 2 -> FE. */

#define CAPTURE_PROPERTY_IMX8X_XRDC_ENABLE		CAPTURE_PROPERTY('I','X','X','E')
	/* R/W		int				XRDC enable (see the enum below.)
	  * XRDC can be enabled to prevent the memory overrun issue, which exists in some silicon revisions. By default,
	  * the capture library enables XRDC if the chip revision is A0 or B0. Please refer to ERR010920 for details.*/

enum imx_xrdc_enable {
	IMX_XRDC_DISABLED,
	IMX_XRDC_ENABLED,
	IMX_XRDC_DEFAULT,
};

#define CAPTURE_PROPERTY_IMX8X_RESET_FLAGS		CAPTURE_PROPERTY('I','X','R','F')
	/* R/W		uint32_t				Instruct the capture libary to perform a reset when a specific error occurs.
	 *						See the bit definition below for available flags. */

/* Reset the ISI channel if the channel reports EARLY_VSYNC error.
  * Note that it doesn't take effect if CAPTURE_DEINTERLACE_WEAVE_MODE is used: in case of WEAVE mode, capture library will decide if a reset is necesary.*/
#define IMX_RESET_ON_EARLY_VSYNC			( 1 << 0)
/* Reset the ISI channel if the channel reports LATE_VSYNC error */
#define IMX_RESET_ON_LATE_VSYNC				( 1 << 1)

#define CAPTURE_PROPERTY_IMX8X_CIPI_CCIR_EN		CAPTURE_PROPERTY('I','X','P','C')
	/* R/W		int				CCIR enable (0: disable; 1: enable.) */

#define CAPTURE_PROPERTY_IMX8X_CIPI_CCIR_EXT_VSYNC_EN	CAPTURE_PROPERTY('I','X','P','V')
	/* R/W		int				CCIR external vsync enable (0: disable; 1: enable.) */

#define CAPTURE_PROPERTY_IMX8X_CIPI_PIXEL_WIDTH		CAPTURE_PROPERTY('I','X','P','W')
	/* R/W		int				Pixel width (0 ~ 65535). */

#define CAPTURE_PROPERTY_IMX8X_CIPI_HSYNC_WIDTH		CAPTURE_PROPERTY('I','X','P','H')
	/* R/W		int				HSYNC pulse width (0 ~ 7) */

#define CAPTURE_PROPERTY_IMX8X_CIPI_VSYNC_WIDTH		CAPTURE_PROPERTY('I','X','P','S')
	/* R/W		int				VSYNC pulse width (0 ~ 65535) */

#define CAPTURE_PROPERTY_IMX8X_CIPI_MASK_VSYNC_CNT	CAPTURE_PROPERTY('I','X','P','M')
	/* R/W		int				Mask vsync counter (0 ~ 3) */

#define CAPTURE_PROPERTY_IMX8X_CIPI_GCLK_MODE_EN	CAPTURE_PROPERTY('I','X','P','G')
	/* R/W		int				Gate clock mode enable (0: disable; 1: enable.) */

#define CAPTURE_PROPERTY_IMX8X_CIPI_UV_SWAP_EN		CAPTURE_PROPERTY('I','X','P','U')
	/* R/W		int				UV swap enable (0: disable; 1: enable.) */

#define CAPTURE_PROPERTY_IMX8X_CSI2_HS_SETTLE		CAPTURE_PROPERTY('I','X','C','H')
	/* R/W		int				HS settle (0 ~ 0x3F) */

/* Customer Definition begin */
#define CAPTURE_PROPERTY_CAMERA_STATUS				CAPTURE_PROPERTY('Q','C','A','S')
	/* R/W		int				Bit variable: bit0-bit3: camera0-camera3 status. status: 0(unlock/unsync) 1(lock&sync). */

#define CAPTURE_PROPERTY_DECODER					CAPTURE_PROPERTY('Q','D','E','C')
#define CAPTURE_DECODER_UNKNOWN						0
#define CAPTURE_DECODER_MAX9286						1
#define CAPTURE_DECODER_MAX96706					2
#define CAPTURE_DECODER_TP2855						3
#define CAPTURE_DECODER_MAX							(CAPTURE_DECODER_TP2855 + 1)

#define CAPTURE_PROPERTY_CAMERA						CAPTURE_PROPERTY('Q','C','A','M')

#define CAPTURE_CAMERA_TYPE_UNKNOWN					0
#define CAPTURE_CAMERA_TYPE_DIGITAL					1
#define CAPTURE_CAMERA_TYPE_ANALOG					2
/* digital cameras */
#define CAPTURE_DCAMERA_MIN							0
#define CAPTURE_DCAMERA_NO1							1 /* TBD */
#define CAPTURE_DCAMERA_NO2							2 /* TBD */
#define CAPTURE_DCAMERA_MAX							100
/* analog cameras */
#define CAPTURE_ACAMERA_MIN							100
#define CAPTURE_ACAMERA_NO1							101 /* TBD */
#define CAPTURE_ACAMERA_NO2							102 /* TBD */
#define CAPTURE_ACAMERA_NO3							103 /* FHD 1920*1080p25 STD */
#define CAPTURE_ACAMERA_MAX							200

#define CAPTURE_PROPERTY_CAMERA_USE					CAPTURE_PROPERTY('Q','C','A','U')
#define CAPTURE_CAMERA_USE_0						0
#define CAPTURE_CAMERA_USE_1						1
#define CAPTURE_CAMERA_USE_2						2
#define CAPTURE_CAMERA_USE_3						3
#define CAPTURE_CAMERA_USE_4						4

#define CAPTURE_PROPERTY_DECODER_ENABLE				CAPTURE_PROPERTY('Q','D','E','E')
#define CAPTURE_DECODER_DISABLE						0
#define CAPTURE_DECODER_ENABLE						1

#define CAPTURE_PROPERTY_CAMERA_TYPE				CAPTURE_PROPERTY('Q','C','C','T')
/* Customer Definition end */

#endif

#if defined(__QNXNTO__) && defined(__USESRCVERSION)
#include <sys/srcversion.h>
__SRCVERSION("$URL: http://svn.ott.qnx.com/product/graphics/branches/release-2.1.x/hardware/wfd/imx8x/caplib/public/vcapture/capture-imx8x-ext.h $ $Rev: 895922 $")
#endif
